package com.ferenc.poi.word;

import org.apache.commons.codec.language.bm.Languages;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * TODO
 *
 * @author <a href="mailto:ferenc.zeng@gmail.com">Ferenc Zeng</a>
 * @since 2022-01-15
 */
public class CreateDocument {

    public static void main(String[] args) throws Exception {

//        createBlandDocument();

        createParagraph();


    }

    private static void createBlandDocument() throws IOException {
        //Blank Document
        XWPFDocument document = new XWPFDocument();

        //Write the Document in file system
        FileOutputStream out = new FileOutputStream(
                new File("createdocument.docx"));
        document.write(out);
        out.close();
        System.out.println(
                "createdocument.docx written successully");

    }

    private static void createParagraph() throws IOException {
        //Blank Document
        XWPFDocument document = new XWPFDocument();
        //Write the Document in file system
        FileOutputStream out = new FileOutputStream(
                new File("create_paragraph.docx"));

        //create Paragraph
        XWPFParagraph paragraph = document.createParagraph();
        XWPFRun run = paragraph.createRun();
        run.setText("At tutorialspoint.com, we strive hard to " +
                "provide quality tutorials for self-learning " +
                "purpose in the domains of Academics, Information " +
                "Technology, Management and Computer Programming Languages.");
        document.write(out);
        out.close();
        System.out.println("createparagraph.docx written successfully");
    }
}


